var os=require("os")
var Utils={
    delay:async function(time){
        return new Promise((resolve, reject) => {
            setTimeout(resolve,time)
        })
    },
    xml2JSON:function(data){
        var xml2js = require('xml2js');
        var xmlParser = new xml2js.Parser({ explicitArray: false, ignoreAttrs: true, async: false });
        var parseResult = {};
        xmlParser.parseString(data, function (err, result) {
            parseResult = result;
        });
        return parseResult;
    },
    getIPAdress:function() {
        var interfaces = os.networkInterfaces();
        for (var devName in interfaces) {
            var iface = interfaces[devName];
            for (var i = 0; i < iface.length; i++) {
                var alias = iface[i];
                if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
                    return alias.address;
                }
            }
        }
        return "";
    }
}
module.exports=Utils;